<!-- 用户个人增删改简历页面 -->
<template>
	<view class="main">
		<u-navbar
			title="个人简历"
			@leftClick="navigateBack"
			safeAreaInsetTop
			fixed
			placeholder
			:autoBack="true"
		></u-navbar>
		<view class="main_head">
			<view class="main_details_box">
				<view class="item-avatar">
					<image :src="imgURL+info.avatar" ></image>
				</view>	
				<view class="item-box">
					<view class="item-info">
						<text class="item-name" v-if="info.name">姓名：{{info.name || ''}}</text>
						<view class="item-auth"><image src="@/static/img/auth.png" ></image></view>
					</view>
					<view class="item-info">
						<view v-if="source && !info.openid" style="color: blue;font-size: 32rpx;" @tap="wxLogin">绑定微信</view>
					</view>
					<view class="item-info">
						<text>{{info.huji || ''}} · {{info.sex || ''}} · {{info.age1 ||''}} · {{info.is_hun ||''}}</text>
					</view>
					<view class="item-phone" v-if="info.phone"> 
						联系电话：	{{info.phone || ""}}
					</view>
					<view class="item-job" v-if="info.job_status">
							在职状态：{{info.job_status || ""}}
					</view>
					<view class="item-map" v-if="info.school">
						毕业学院：{{info.school || ""}}
					</view>
				</view>
			</view>
			<view class="item-skill">
				<image src="@/static/img/map-lan.png" ></image>
				{{info.address || ""}}
			</view>
		</view>
		<view class="main_details_content">
			<view class="main_details_content_box">
				<view class="main_details_title" style="margin-bottom: 20rpx;display: flex; justify-content: space-between;align-items: center;">
					<view>求职意向</view> 
					<view v-if="source" style="color: blue;font-size: 32rpx;" @click="goto('/resume/basic?edit=1')">修改</view>
				</view>
				<view class="main_details_box css3order" style="width: 600rpx;">
					<view class="main_details_box_job" style="margin: 0;">
						<view class="main_details_box_job_time">
							工作经验：{{info.work_y ? info.work_y :''}}  -  {{info.education ? info.education :''}}
						</view>
					<view class="main_details_box_job_time" v-if="info.skill">
						技能：{{info.skill || ""}}
					</view>
						<view class="main_details_box_job_time">
							期望城市：{{info.expect_city ? info.expect_city :''}}
						</view>
						<view class="main_details_box_job_time">
							期望薪资：{{info.salary ? info.salary :''}}
						</view>
						<view class="main_details_box_job_intro">
							人生规划：{{info.plan ? info.plan :''}}
						</view>
					</view>
				</view>
			</view>
			<view class="main_details_content_box" style="margin-top:60rpx">
				<view class="main_details_title" style="display: flex; justify-content: space-between;align-items: center;">
				<view>视频展示</view>
					<view v-if="source" style="color: blue;font-size: 32rpx;" @click="goto('/resume/video')">{{info.video_url ? "修改" : "添加"}}</view>
				</view>
				<view class="main_details_box" v-if="info.is_open_video == 1">
					<view class="main_details_box_job">
						<view v-if="info.video_url">
							<video style="width: 560rpx;height: 300rpx;" :src="imgURL+info.video_url"></video>
							<!-- <video-player :title="'个人视频简历'" :videoSrc="imgURL+info.video_url" :videoType="'mp4'">
							 </video-player> -->
						</view>
						<view class="main_details_box_job_intro">
							{{info.intro}}
						</view>
					</view>
				</view>
			</view>
			<view class="main_details_content_box" style="margin-top:60rpx">
				<view class="main_details_title" style="display: flex; justify-content: space-between;align-items: center;">
				<view>作品集</view>
					<view v-if="source" style="color: blue;font-size: 32rpx;" @click="goto('/resume/image')">{{imgs.length > 0 ? "修改" : "添加"}}</view>
				</view>
				<view class="main_details_box" v-if="imgs.length > 0">
					<view class="main_details_box_job">
						<block v-for="(item,index) in imgs" :key="index">
							<image @click="shoImg(index)" style="width: 170rpx;height: 170rpx;margin-left: 20rpx;margin-bottom: 20rpx;" :src="imgURL+item"></image>
						</block>
					</view>
				</view>
			</view>
		</view>
		<view class="main_details_content" style="padding-bottom: 140rpx;">
			<view class="main_details_content_box">
				<view class="main_details_title" style="display: flex; justify-content: space-between;align-items: center;">
					<view>工作经验</view>
					<view v-if="source" style="color: blue;font-size: 32rpx;" @click="openmodel(null)">添加</view>
				</view>
				<block v-for="(item,index) in info.explist">
					<view class="main_details_box">
						<view class="main_details_box_job_left">
							<image style="width:50rpx;height:50rpx" src="@/static/img/dian1.png"></image> 
						</view>
						<view class="main_details_box_job">
							<view class="main_details_box_job_company">
								<view>在职时间：{{item.startDate || ""}}-{{item.endDate || ""}}</view>
							</view>
							<view class="css3order" style="width: 520rpx;">
								<view class="main_details_box_job_time" style="color: #333333;font-size: 30rpx;font-weight: bold;">
									公司：{{item.companyName || ""}} 
								</view>
								<view class="main_details_box_job_time">
									岗位：{{item.positionName || ""}}</view>
								<view class="main_details_box_job_intro">
									负责：{{item.workContent || ""}}
								</view>
								<view v-if="source" style="overflow: auto;margin-bottom: 10rpx;">
									<view style="display: flex;align-items:center;float:right;justify-content: space-between;">
										<view style="color: blue;font-size: 32rpx;padding:10rpx 20rpx;" @click="openmodel(item.exp_id)">修改</view>
										<view style="color: blue;font-size: 32rpx;padding:10rpx 20rpx;" @click="delExp(item.exp_id)">删除</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
		</view>
		<u-modal
			:title="title"
			:show="showModal"
			showCancelButton
			asyncClose
			@confirm="confirm"
			@cancel="() => showModal = false"
		>
			<u--form
				labelPosition="left"
				:model="form"
				ref="form"
			>
				<u-form-item
					label="公司名称"
					prop="companyName"
					borderBottom
					labelWidth="80"
				>
					<u--input
						v-model="form.companyName"
						border="none"
						placeholder="公司名称"
					></u--input>
				</u-form-item>
				<u-form-item
					label="所属部门"
					prop="department"
					borderBottom
					labelWidth="80"
				>
					<u--input
						v-model="form.department"
						border="none"
						placeholder="所属部门"
					></u--input>
				</u-form-item>
				<u-form-item
					label="职位名称"
					prop="positionName"
					borderBottom
					labelWidth="80"
				>
					<u--input
						v-model="form.positionName"
						border="none"
						placeholder="职位名称"
					></u--input>
				</u-form-item>
				<u-form-item
					label="入职时间"
					prop="startDate"
					borderBottom
					labelWidth="80"
				>
					<u--input
						v-model="form.startDate"
						border="none"
						placeholder="入职时间"
					></u--input>
				</u-form-item>
				<u-form-item
					label="离职时间"
					prop="endDate"
					borderBottom
					labelWidth="80"
				>
					<u--input
						v-model="form.endDate"
						border="none"
						placeholder="离职时间"
					></u--input>
				</u-form-item>
				<u-form-item
					label="负责项目"
					prop="workContent"
					labelWidth="80"
				>
				</u-form-item>
				<u-form-item>
					<u--textarea
						placeholder="不低于3个字"
						v-model="form.workContent"
						:maxlength='800'
						count
					></u--textarea>
				</u-form-item>
			</u--form>
		</u-modal>
		
		<block  v-if="source"><Tabbar :count="2"></Tabbar></block>
	</view>
</template>

<script>
	import util from "@/utils/utils.js"
	import Tabbar from "@/components/Tabbar"
	import videoPlayer from '@/components/video'
	import {wechatAuth} from '@/api/user.js'
	import { getMyResume,saveExperience,getexperience,delExperience } from '@/api/resume.js'
	import { imgURL } from '@/utils/config'
	export default {
		components: {
			videoPlayer,
			Tabbar
		},
		data() {
			return {
				source:true,
				imgURL:imgURL,
				id:'',
				info: '',
				height:0,
				showModal:false,
				imgs:[],
				form:{
					companyName:'',//公司名称
					department:'',//所属部门
					positionName:'',//职位名称
					startDate:'',//入职时间
					endDate:'',//离职职时间
					workContent:'',//项目内容
				},
				userInfo:{
					encryptedData:'',
					iv:'',
					code:'',
				}
			}
		},
		onLoad(option) {
			const that = this
			if(option){
				this.id = option.id
			}
			
			if(option.source){
				this.source = false
			}
			 uni.getSystemInfo({
					success: (res)=> {
						that.height = res.windowHeight- uni.upx2px(100)-260 //获取系统信息，可使用窗口的高度
					}
			});
			this.getResume()
		},
		methods: {
			//获取信息
			getResume() {
				getMyResume({}).then(res=>{
					if(res.code == 200){
						this.info = res.data
						if(res.data.imgs){
							this.imgs = JSON.parse(res.data.imgs)
						}
					}
				})
			},
			//工作经历弹窗
			openmodel(exp_id) {
				this.showModal = true
				this.title = "添加工作经验"
				this.form = {
					companyName:'',//公司名称
					department:'',//所属部门
					positionName:'',//职位名称
					startDate:'',//入职时间
					endDate:'',//离职职时间
					workContent:'',//项目内容
				}
				if(exp_id){
					this.title = "修改工作经验"
					getexperience({exp_id:exp_id}).then((res)=>{
						if(res.code == 200){
							this.form = res.data
							this.form = {
								exp_id:res.data.exp_id,
								companyName:res.data.companyName,//公司名称
								department:res.data.department,//所属部门
								positionName:res.data.positionName,//职位名称
								startDate:res.data.startDate,//入职时间
								endDate:res.data.endDate,//离职职时间
								workContent:res.data.workContent,//项目内容
							}
						}
						else{
							return uni.showToast({
								title:res.msg,
								duration: 2000,
								icon:'none'
							});
						}
					})
				}
			},
			
			//提交
			confirm(){
				let that= this
				if (this.form.companyName == "") {
					return uni.showToast({
						icon: 'none',
						title: '请填写公司名称'
					});
				}
				if (this.form.department == "") {
					return uni.showToast({
						icon: 'none',
						title: '请填写所属部门'
					});
				}
				if (this.form.positionName == "") {
					return uni.showToast({
						icon: 'none',
						title: '请填写职位名称'
					});
				}
				if (this.form.startDate == "") {
					return uni.showToast({
						icon: 'none',
						title: '请填写入职时间'
					});
				}
				if (this.form.endDate == "") {
					return uni.showToast({
						icon: 'none',
						title: '请填写离职时间'
					});
				}
				if (this.form.workContent == "") {
					return uni.showToast({
						icon: 'none',
						title: '请填写负责的项目内容'
					});
				}
				saveExperience(this.form).then((res)=>{
					this.showModal = false
					if(res.code == 200){
						uni.showToast({
							title:res.msg,
							duration: 2000,
							icon:'none',
							success() {
								that.getResume()
							}
						});
					}
					else{
						return uni.showToast({
							title:res.msg,
							duration: 2000,
							icon:'none'
						});
					}
				})
			},
			
			wxLogin(){
			  // #ifdef MP-WEIXIN
				var that = this
				uni.getUserProfile({
					desc: '登录',
					success: (res) => {
						that.userInfo.iv = res.iv
						that.userInfo.encryptedData = res.encryptedData
						let code = that.getCode()
						if(code){
							that.userInfo.code = code
							that.wechatlogin()
						}else{
							uni.login({
								success: res => {
									that.loadModal = true
									that.userInfo.code = res.code
									var storage = {
										'code':that.userInfo.code,
										'time': (new Date()).getTime(),
									}
									uni.setStorageSync('wechatcode', storage)
									that.wechatlogin()
								}
							});
						}
					},
					fail: (res) => {
						return uni.showToast({
							title:"授权微信信息异常"+res,
							duration: 2000,
							icon:'none'
						});  
					}
				});
				//#endif
			},
			getCode(){
				const info = uni.getStorageSync('wechatcode');
					if (info){
						var before = new Date().getTime() - 5 * 3600;
						if (before < info.time){
							return info.code
						}else{
							uni.removeStorageSync('wechatcode')
							return false
						}
					}
					else{
						return false
					}
			},
			
			wechatlogin(){
				let that = this
				wechatAuth(that.userInfo).then(res => {
					if(res.code == 200){
						uni.showToast({
							title:res.msg,
							duration: 2000,
							icon:'none',
							success() {
								that.getEnterprise()
							}
						});
					}
					else{
						uni.showToast({
							icon: 'none',
							title: res.msg
						});
					}
				});
			},
			
			delExp(id){
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要删除吗？',
					success: function (res) {
						if (res.confirm) {
							delExperience({id:id}).then((res)=>{
								uni.showToast({
									title:res.msg,
									duration: 2000,
									icon:'none',
									success() {
										that.getResume()
									}
								});
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			
			// 新增图片
			async upload() {
				let _this = this;
				util.uploadFile("/user/Upload").then((res)=>{
					if(res.code == 200){
						uni.showToast({
							title:res.msg,
							duration: 2000,
							icon:'none',
							success() {
								_this.form.avatar = res.data
							}
						});
					}
					else{
						return uni.showToast({
							title:res.msg,
							duration: 2000,
							icon:'none'
						});
					}
				})
			},
			//退出登录
			outlogin(){
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要退出账号吗？',
					success: function (res) {
						if (res.confirm) {
							util.clear()
							uni.redirectTo({
								url: '/pages/login/login'
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			
			shoImg(index){
				var imgbox = [];
				for(let i in this.imgs){
					imgbox.push(this.imgURL+this.imgs[i])
				}
				uni.previewImage({
					//当前显示图片
					current: imgbox[index],
					//所有图片
					urls: imgbox
				})
				//util.previewImage(index)
			},
			
			goto(tourl) {
				uni.navigateTo({
					url: tourl
				});
			}
		},
	}
	
</script>

<style lang="scss">
	@import "@/static/css/resumedetails.scss";
</style>